package com.atguigu.staservice.scheduled;

import com.atguigu.staservice.service.StatisticsDailyService;
import com.atguigu.staservice.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author panghl
 * @Date 2021/2/25 11:14
 * @Description 每五秒统计注册人数--定时任务
 **/
@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService staService;

    @Scheduled(cron = "0/5 * * * * ? ")
    public void task1() {
        System.out.println("*****------****每五秒执行一次");
    }

    //每天凌晨一点执行
    @Scheduled(cron = "0 0 1 * * ? ")
    public void task2() {
        System.out.println("*****------****获取上一天日期");
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        staService.registerCount(day);
    }

}
